//
//  LcMacroWeakStrong.h
//  18Birdies
//
//  Created by weihuazhang on 2016/12/7.
//  Copyright © 2016年 Lc. All rights reserved.
//

#ifndef LcMacroWeakStrong_h
#define LcMacroWeakStrong_h

#import "metamacros.h"

#undef LcWeak
#define LcWeak(...) @weakify(__VA_ARGS__)
#define LcWeakSelf  LcWeak(self)

#undef LcStrong
#define LcStrong(...) @strongify(__VA_ARGS__)
#define LcStrongSelf  LcStrong(self)



#define weakify(...) \
    ext_keywordify \
    metamacro_foreach_cxt(ext_weakify_,, __weak, __VA_ARGS__)

#define strongify(...) \
    ext_keywordify \
    _Pragma("clang diagnostic push") \
    _Pragma("clang diagnostic ignored \"-Wshadow\"") \
    metamacro_foreach(ext_strongify_,, __VA_ARGS__) \
    _Pragma("clang diagnostic pop")

#define ext_weakify_(INDEX, CONTEXT, VAR) \
    CONTEXT __typeof__(VAR) metamacro_concat(VAR, _weak_) = (VAR);

#define ext_strongify_(INDEX, VAR) \
    __strong __typeof__(VAR) VAR = metamacro_concat(VAR, _weak_);

#if DEBUG
#define ext_keywordify autoreleasepool {}
#else
#define ext_keywordify try {} @catch (...) {}
#endif

#endif /* LcMacroWeakStrong_h */
